import service from "@/utils/request";

import { ElNotification } from "element-plus";
// 发送GET请求
export const get = (url, data = {}) =>
  service
    .get(url, {
      params: data,
    })
    .then((response) => response.data)
    .catch(function (error) {
      if (error.response) {
        ElNotification({
          title: error.response.status,
          message: error.response.data || "请求失败",
          type: "error",
        });
      } else if (error.request) {
        ElNotification({
          title: error.response.status,
          message: error.request || "请求失败",
          type: "error",
        });
      } else {
        ElNotification({
          title: error.response.status,
          message: error.message || "请求失败",
          type: "error",
        });
      }
      console.log(error.config);
    });

// 发送POST请求
export const post = (url, data = {}) =>
  service
    .post(url, data)
    .then((response) => response.data)
    .catch(function (error) {
      console.log(error);
      if (error.response) {
        ElNotification({
          title: error.response.status,
          message: error.response.data || "请求失败",
          type: "error",
        });
      } else if (error.request) {
        ElNotification({
          title: error.response.status,
          message: error.request || "请求失败",
          type: "error",
        });
      } else {
        ElNotification({
          title: error.response.status,
          message: error.message || "请求失败",
          type: "error",
        });
      }
      console.log(error.config);
    });
